import 'package:flutter_layout/page/case.dart';
import 'package:flutter_layout/page/home.dart';
import 'package:flutter_layout/page/my.dart';
import 'package:flutter_layout/page/router.dart';
import 'package:flutter_layout/widget/layout.dart';
import 'package:go_router/go_router.dart';

final router = GoRouter(
    initialLocation: "/case",
    routes: [
      /**
       * 有状态tabbar页面配置项
       * 需要显示tabbar栏的在相关tab下添加路由
       * 不需要的全部放在外部routes中
       */
      StatefulShellRoute.indexedStack(
        branches: [
          StatefulShellBranch(
            initialLocation: "/home",
            routes: [
              GoRoute(path: "/home", builder: (context, state) => Home()),
            ],
          ),
           StatefulShellBranch(
            initialLocation: "/case",
            routes: [
              GoRoute(path: "/case", builder: (context, state) => Case()),
            ],
          ),
          StatefulShellBranch(
            initialLocation: "/my",
            routes: [
              GoRoute(path: "/my", builder: (context, state) => My()),
            ],
          ),
        ],
        builder: (context, state, navigationShell) =>
            Layout(navigationShell: navigationShell),
      ),
      GoRoute(
        // 路由path参数传递
          path: '/routerView/:id',
          builder: (context, state) =>
              RouterView(id: state.pathParameters['id']!)),
      GoRoute(
        // 路由url参数传递
          path: '/routerView',
          builder: (context, state) =>
              RouterView(id: state.uri.queryParameters['id']!)),
    ],
    redirect: (context, state) {
      // 路由拦截器 可以再次进行数据拦截
      // return null 表示正常跳转
      // return '/home'; 表示强制跳转到/home
      return null;
    });
